package com.changwu.cwbase.base;

import android.app.Activity;
import android.app.Application;
import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;


import com.changwu.cwbase.R;

import java.util.HashMap;
import java.util.Map;

public class BasicDialog extends Dialog {
	protected View head;// 头部
	protected TextView title;// 标题
	protected TextView content;// 内容
	protected Button cancel;// 取消按钮
	protected Button submit;// 确认按钮
	protected Context context;
	// 保存要传送的信息
	protected Map<String, Object> data;
	// dialog监听控件
	protected OnDialogListener listener;

	public BasicDialog(Context context) {
		super(context, R.style.AppDialog);
		// TODO Auto-generated constructor stub
		data = new HashMap<String, Object>();
		this.context = context;
	}

	protected BasicDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
		super(context, cancelable, cancelListener);
		// TODO Auto-generated constructor stub
		data = new HashMap<String, Object>();
		this.context = context;
	}

	public interface OnDialogListener {
		public void submit(Map<String, Object> data);

		public void cancel();
	}

	public OnDialogListener getListener() {
		return listener;
	}

	public void setListener(OnDialogListener listener) {
		this.listener = listener;
	}

	@Override
	public void show() {
		/**
		 * 如果程序被销毁了，就不就TextAppearance再显示 对话框
		 */
		if (context instanceof Activity) {
			if (!((Activity) context).isFinishing()) {
				super.show();
			}
		} else if (context instanceof Application) {
			super.show();
		}
	}

	public void setTitle(  CharSequence t) {
		if (title != null) {
			title.setText(t);
		}
	}

	public void setContent( CharSequence t) {
		if (content != null) {
			content.setText(t);
		}
	}
	public void setSubmit( CharSequence t) {
		if (submit != null) {
			submit.setText(t);
		}
	}
	public void setCancel( CharSequence t) {
		if (cancel != null) {
			cancel.setText(t);
		}
	}
}